package mystack;

import java.lang.reflect.Array;

/**
 * Created by Administrator on 2017/3/16.
 */
public class SeqStack<E> implements MyStack<E> {
    private  E[] date;
    private int maxsize;
    private int top;

    public SeqStack(Class<E> type, int maxsize) {
        date = (E[]) Array.newInstance(type,maxsize);
        this.maxsize = maxsize;
        top=-1;
    }

    @Override
    public E push(E item) {
        if ( !isFull()){
            date[++top]=item;
            return item;
        }
        return null;
    }

    @Override
    public E pop() {
        E item =null;
        if (!isEmpty()){
            item = date[top--];
        }
        return item;
    }

    @Override
    public E peak() {
        E item =null;
        if (!isEmpty()){
            item=date[top];
        }
        return item;
    }

    @Override
    public boolean isEmpty() {
        if (top==-1){
            return true;
        }
        return false;
    }

    @Override
    public boolean isFull() {

        return false;
    }

    @Override
    public int getsize() {
        return 0;
    }
}
